package com.example.redis1;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.Tuple;

import java.util.Set;

public class RedisDemo2 {
    public static void main(String[] args) {
        //创建一个Jedis连接池
        JedisPoolConfig config = new JedisPoolConfig();
        //最小容量（初始容量）
        config.setMaxIdle(5);
        //最大容量
        config.setMaxTotal(50);
        //等待超时(单位ms)
        config.setMaxWaitMillis(5000);

        String host = "192.168.247.132";
        int port = 6379;

        JedisPool jp = new JedisPool(config,host,port);

        //基于连接池获取jedis连接对象
        Jedis jedis = jp.getResource();

        //执行操作
        Set<Tuple> tuples = jedis.zrevrangeWithScores("wel_man", 0, -1);

        tuples.forEach(tuple -> {
            String welName = tuple.getElement();
            double score = tuple.getScore();

            System.out.println(welName + "获得票数为:" + score);
        });

        //释放资源(归还连接)
        jedis.close();
    }
}
